import { removeUserInfo } from '@/utils/user'
import router from '@/router'
export default {
  namespaced: true,
  state: {
    token: localStorage.getItem('token') || '',
    role: localStorage.getItem('role') || '',
    userInfo: localStorage.getItem('userInfo')
      ? JSON.parse(localStorage.getItem('userInfo'))
      : {}
  },
  mutations: {
    // 登陆成功后 赋值 state给 token role userInfo
    INIT_USER (state, { token, role, userInfo }) {
      state.token = token
      state.role = role
      state.userInfo = userInfo
    },
    USER_LOGOUT () {
      removeUserInfo()
      router.go(0)
    }
  }
}
